#ifndef __TIMER_H__
#define __TIMER_H__

#include <string>
#include <functional>
#include "plat/nonecopyable.h"

class Timer : public NoneCopyable
{
public:
    enum class TimerType 
    {
        OneShot = 0,
        Period
    };

public:
    explicit Timer();
    explicit Timer(int interval, TimerType type = TimerType::Period);
    virtual ~Timer();

public:
    void SetInterval(int interval);
    int GetInterval();
    void SetTimerType(TimerType type);
    TimerType GetTimerType();

    void SetElapsed(std::function<void(Timer &timer)> func);

    void Start();
    void Restart();
    void Stop();
    bool IsRunning();

public:
    static void SingleShot(int ms, const std::function<void(void)> &&func);

public:
    void CallImpl();

private:
    void CreateTimer();
    void DeleteTimer();
    
private:
    int m_interval = 10;
    bool m_isRunning = false;  //os timer 不是实时更新running状态的，这里加个状态...
    TimerType m_timerType = TimerType::Period;
    std::function<void(Timer &timer)> m_func = nullptr;

    void *m_timerHandle = nullptr;
};

#endif // __TIMER_H__
